package com.zsk.shop;

import com.zsk.shop.common.constant.RedisKeys;
import com.zsk.shop.common.utils.RedisUtil;
import com.zsk.shop.entity.DataDictionary;
import com.zsk.shop.service.DataDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 初始化数据字典
 *
 * @author Ys
 * @version 1.0
 * @date 2021/3/20 13:55
 */
@Component
@Order(value = 2)
@Slf4j
public class AreaData implements CommandLineRunner {

    @Resource
    private DataDictionaryService dataDictionaryService;

    @Override
    public void run(String... args) {
        log.info("***************开始加载省数据***************");
        List<DataDictionary> listT = dataDictionaryService.getDataDictionaryInfo();
        for (DataDictionary obj : listT) {
            RedisUtil.delete(obj.getKey());
            RedisUtil.set(RedisKeys.dictionaryKey(obj.getKey()), obj.getValue());
        }
        log.info("***************结束加载省数据***************");
    }
}
